package com.foyekoo.project001.utils;

import android.content.Intent;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.util.Log;

import com.foyekoo.project001.App;
import com.foyekoo.project001.config.DataConfig;
import com.foyekoo.project001.config.ReqData;
import com.foyekoo.project001.service.UsbService;

import static com.foyekoo.project001.utils.ReadThread.ACTION_DATA_RECIEVE;
import static com.foyekoo.project001.utils.ReadThread.EXTRA_DATA;

public class WriteThread extends BaseThread {

    private UsbDeviceConnection connection;
    private UsbEndpoint[][] endpoint;

    public void setConnection(UsbDeviceConnection connection, UsbEndpoint[][] point) {
        this.connection = connection;
        this.endpoint = point;
    }

    @Override
    public void run() {
        super.run();
        while(isRunning) {
            try {
                Thread.sleep(50);
                ReqData reqData = UsbService.reqData.take(); //如果这里没有东西 那么会是一个阻塞
                byte[] data = reqData.getDatas();
                //byte[] data = "123\r\n".getBytes();

                //byte[] data = "12321321312".getBytes();
               // byte[] data = {(byte)0x58,(byte)0x01,(byte)0x03,(byte)0x01,(byte)0x03,(byte)0x01,(byte)0x03, (byte) 0x85};

                connection.bulkTransfer(endpoint[1][0], data, data.length, 30);



            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
